package com.mygdx.game.Stage;


import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.*;
import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.mygdx.game.MyGdxGame;
import com.mygdx.game.Scenes.ActiveCharacter;
import com.mygdx.game.Screens.HomeScreen;

import javax.swing.*;
import javax.swing.plaf.basic.BasicInternalFrameTitlePane;

public class DialogueStage extends Stage {
  private float i = 100;
  private Stage stage;
  private int click_Count= 0;
  private String background;
  private Image Topic;
  private Button Topic1;
  private ActiveCharacter activeCharacter;
  private int positionX;
  private int positionY;
  private Texture texture;
    private Texture texture2;
    public DialogueStage(String background,int positionX,int positionY) {
        super();
        this.background = background;
        this.positionX = positionX;
        this.positionY = positionY;
        init();
    }
    public int getClick_Count(){
        return click_Count;
    }
    public Actor getactor(){
        return activeCharacter;
    }

    private void init() {
       // activeCharacter = new ActiveCharacter("Character/GreenNPC",MyGdxGame.V_WIDTH/2,MyGdxGame.V_HEIGHT/2);
         this.stage = this;
        texture = new Texture(Gdx.files.internal(background)); //"GroupProject/image/story.png"
        texture2 = new Texture(Gdx.files.internal("start/load.png"));
        Button.ButtonStyle style = new Button.ButtonStyle();
        style.up = new TextureRegionDrawable(new TextureRegion(texture));
        style.down = new TextureRegionDrawable(new TextureRegion(texture2));

//        Topic = new Image(texture);
//        Topic.setSize(200,200);


        Topic1 = new Button(style);

        Topic1.setSize(i,i);
        Topic1.setPosition(MyGdxGame.V_WIDTH/2,MyGdxGame.V_HEIGHT/2);

        MoveByAction action = Actions.moveBy(MyGdxGame.V_WIDTH/2,MyGdxGame.V_HEIGHT/2,3);
        RotateByAction action1 = Actions.rotateBy(90,3);
        MoveByAction action2 = Actions.moveBy(0,0,3);
        SequenceAction sequenceAction = Actions.sequence(action , action1,action2);
        sequenceAction.setActor(Topic1);

        RepeatAction repeatAction = Actions.repeat(RepeatAction.FOREVER,sequenceAction);

        Topic1.addAction(repeatAction);
        activeCharacter.addAction(repeatAction);

        this.addActor(Topic1);
        this.addActor(activeCharacter);


        Topic1.addListener(new ChangeListener() {
            @Override
            public void changed(ChangeEvent event, Actor actor) {
                i+=100;

                click_Count +=1;
                System.out.println(click_Count);
              if (click_Count==3){
                  click_Count=0;
                  stage.getRoot().removeActor(activeCharacter);
              }
              if (click_Count == 1){
                  stage.addActor(activeCharacter);
              }
                actor.setSize(i,i);
                if (i>600){
                    i=100;
                }
            }
        });







    }
}
